package Mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import pojo.ExchangeRecord;

import java.util.List;

@Mapper
public interface ExchangeRecordMapper {
    @Select("SELECT * FROM exchange_record WHERE user_id = #{userId} ORDER BY exchanged_at DESC")
    List<ExchangeRecord> findByUserId(Long userId);

    @Insert("INSERT INTO exchange_record(user_id, product_id, quantity, total_points, exchanged_at) " +
            "VALUES(#{userId}, #{productId}, #{quantity}, #{totalPoints}, NOW())")
    int insert(ExchangeRecord record);
}
